import QtQuick 2.11
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.11
import FluentUI

/**EMAnalysisDetail.qml
  * 此组建负责渲染计算得到的相关数据
  * 由于渲染的数据较多，所以采用另外独立一个窗口的模式
  * 对外提供setDrawJson，传入json str用于触发渲染逻辑
  *
  * 简单创建逻辑如下:
        var component = Qt.createComponent("qrc:/ClientAnalysis/UI/ImageResult/ImageArea.qml")
        var win = component.createObject()
        win.loadJsonStr(s)
        win.show()
  */


FluWindow {
    id: root
    minimumWidth: 1280
    minimumHeight: 720
    fixSize: false
    closeDestory: true
    property string drawJson: ""
    property string winTitle: "Result Preview"

    appBar: FluAppBar {
        height: 30
        title: winTitle
        showDark: false
        z:7
    }

    Row{
        EMColumnDetail{
            id: ori
            title: "Ori Data"
            width: root.width / 2
            height: root.height
        }

        EMColumnDetail{
            id: enh
            title: "Enh Data"
            width: root.width / 2
            height: root.height
        }
    }

    function setDrawJson(jsonStr){
        drawJson = jsonStr
        let oriDict = paserFromJsonStr(jsonStr, true)
        let enhDict = paserFromJsonStr(jsonStr, false)

        ori.jsonDraw(oriDict)
        enh.jsonDraw(enhDict)
    }

    function paserFromJsonStr(jsonStr, useOri) {
        let res = JSON.parse(jsonStr)['res']

        let json = JSON.parse(res)

        let d = {}
        if (useOri === true) d = json['ori']
        else d = json['enh']

        let returnDict = {}
        returnDict['file'] = d['file']
        returnDict['seg'] = d['seg']
        returnDict['cam'] =  d['grade']['cam']
        returnDict['camplus'] = d['grade']['cam_plus']
        returnDict['chart'] = d['grade']['pie']

        return returnDict
    }
}
